<?php

include("config.php");
if (!isset($_SESSION["auser"]) || $_SESSION["auser"] == "" || $_SESSION['agroup'] != "WEB_ADMIN") 
{
echo '{"query": "Unit","suggestions": []}';
die();
}

$db_www = new DB($server_username,$server_pass,$server_db,$server,$driver);



if (isset($_REQUEST["query"])){
	$key = iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["query"]));
	$filter = "AND ( n60_pav2 LIKE '%$key%')";
	$allusers_query = str_replace("<filter>", $filter, $allusers_query);

	$users = $db_www->returnList($allusers_query);
	if (!empty($users)) {
		echo "{\n";
		echo '"query": "Unit","suggestions": [';
		$i = 0;
		foreach ($users as $user) {
			if ($i != 0) {
				echo ",";
			}
		  echo '"';
		  echo str_replace("\"",'\"',iconv('windows-1257','UTF-8',trim($user["n60_pav2"])));
		  echo '"';
		  $i++;
		}
		echo ']';
		echo "}";
	} else {
		echo '{"query": "Unit","suggestions": []}';
	}
} else {
	echo '{"query": "Unit","suggestions": []}';
}
?>